/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Entity.Etbl_Tour_bookings;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author mrteo
 */
public class DALtbl_Tour_bookings extends BaseConnection {
    CallableStatement clbStm=null;
    ResultSet rs=null;
    public boolean addtbl_Tour_bookings(Etbl_Tour_bookings obj){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Tour_bookings_add(?,?,?,?,?,?)}");
            clbStm.setInt("tourbookings_Id", obj.getTourbookings_Id());
            clbStm.setInt("participants",obj.getParticipants());
            clbStm.setFloat("price",obj.getPrice());   
            clbStm.setString("create_on", obj.getCreate_on());
            clbStm.setString("modified", obj.getModified());
            clbStm.setInt("status", obj.getStatus());
            clbStm.execute();
            clbStm.close();
            releaseConnection();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Tour_bookings.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    public boolean edittbl_Tour_bookings(Etbl_Tour_bookings obj){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Tour_bookings_update(?,?,?,?,?,?,?,?,?)}");
            clbStm.setInt("tourbookings_Id", obj.getTourbookings_Id());
            clbStm.setInt("userId", obj.getUserId());
            clbStm.setInt("packagetour_Id", obj.getPackagetour_Id());
            clbStm.setInt("participants",obj.getParticipants());
            clbStm.setFloat("price",obj.getPrice());   
            clbStm.setString("create_on", obj.getCreate_on());
            clbStm.setString("modified", obj.getModified());
            clbStm.setInt("status", obj.getStatus());
            clbStm.execute();
            rs.close();
            releaseConnection();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Tour_bookings.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    public boolean deletetbl_Tour_bookings(int  tourbookings_Id){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Tour_bookings_delete(?)}");
            clbStm.setInt("tourbookings_Id", tourbookings_Id);
            clbStm.execute();
            clbStm.close();
            releaseConnection();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Tour_bookings.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public Etbl_Tour_bookings getOnetbl_Tour_bookings(int tourbookings_Id){
          Etbl_Tour_bookings obj=new Etbl_Tour_bookings();
          try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Tour_bookings_get(?)}");
            clbStm.setInt("tourbookings_Id",tourbookings_Id);              
            rs=clbStm.executeQuery();            
            while(rs.next()){                            
                obj.setTourbookings_Id(rs.getInt("tourbookings_Id"));
                obj.setParticipants(rs.getInt("participants"));
                obj.setPrice(rs.getFloat("desciptions"));
                obj.setCreate_on(rs.getString("create_on"));
                obj.setModified(rs.getString("modified")); 
                obj.setStatus(rs.getInt("status"));
                obj.setUserId(rs.getInt("userId"));
                obj.setUser_Name(rs.getString("user_name"));
                obj.setPackagetour_Id(rs.getInt("packagetour_Id"));
                obj.setPackagetour_Name(rs.getString("packagetour_name"));
            }            
            clbStm.close();
            rs.close();
            releaseConnection();
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Tour_bookings.class.getName()).log(Level.SEVERE, null, ex);
            
        }finally{
              return obj;
          }
      }
    public ArrayList getListTour_Bookings(String orderBy, String ASCorDESC, String WhereClause, int PagingIndex, int PagingSize){
        try {
            ArrayList TourBookingsList=new ArrayList();
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Tour_bookings_getpaged(?,?,?,?,?)}");
            clbStm.setString("OrderBy", orderBy);
            clbStm.setString("TangGiam", ASCorDESC);
            clbStm.setString("WhereClause", WhereClause);
            clbStm.setInt("PageIndex", PagingIndex);
            clbStm.setInt("PageSize", PagingSize);
            rs=clbStm.executeQuery();
            DALTotalPageIndex.getTotalPage("tbl_Tour_bookings", WhereClause, PagingSize);
            while(rs.next()){
                Etbl_Tour_bookings obj=new Etbl_Tour_bookings();
                obj.setTourbookings_Id(rs.getInt("tourbookings_Id"));
                obj.setParticipants(rs.getInt("participants"));
                obj.setPrice(rs.getFloat("desciptions"));
                obj.setCreate_on(rs.getString("create_on"));
                obj.setModified(rs.getString("modified")); 
                obj.setStatus(rs.getInt("status"));
                obj.setUserId(rs.getInt("userId"));
                obj.setUser_Name(rs.getString("user_name"));
                obj.setPackagetour_Id(rs.getInt("packagetour_Id"));
                obj.setPackagetour_Name(rs.getString("packagetour_name"));
                TourBookingsList.add(obj);
            }
            clbStm.close();
            rs.close();
            releaseConnection();
            return TourBookingsList;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Tour_bookings.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
}
